package com.hot100.mid;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 子集 回溯
 * @date 2022/8/19 17:26
 */
public class Demo23 {
    static  List<List<Integer>>  res =new ArrayList<>();


    public static void main(String[] args) {
          int[] nums={1,2,3};
        List<List<Integer>> subsets = subsets(nums);
        System.out.println(subsets);
    }
     public  static List<List<Integer>> subsets(int[] nums) {
          List<Integer>  temp=new ArrayList<>();
          addTempRes(temp,nums,0);
          return res;
    }

    private static void addTempRes(List<Integer> temp, int[] nums, int start) {
        res.add(new ArrayList<>(temp));
         if(start==nums.length){
             return;
         }
        for (int j = start; j < nums.length; j++) {
                temp.add(nums[j]);
                addTempRes(temp,nums,j+1);
                temp.remove(temp.size()-1);

        }
    }
}
